"""
    1.静态IP调用：

    2.动态ip调用(DHCP):

"""

from os import system, getcwd
from time import sleep
# from all_function_of_connect import url_post, url_loginOut
from requests import get, post

post_information = {
    '0MKKey': '123456',
    'buttonClicked': '',
    'cmd': '',
    'DDDDD': '201613010215@cmcc',
    'err_flag': '',
    'Login': '',
    'para': '00',
    'password': '',
    'R1': '0',
    'R2': '',
    'R3': '0',
    'R6': '0',
    'redirect_url': '',
    'upass': '063918',
    'user': '',
    'username': ''}
hander_Dict = {
    'Accept': ' text/html, application/xhtml+xml, image/jxr, */*',
    'Accept-Encoding': ' gzip, deflate',
    'Accept-Language': ' zh-Hans-CN, zh-Hans; q=0.8, en-GB; q=0.5, en; q=0.3',
    'Cache-Control': ' no-cache',
    'Connection': ' Keep-Alive',
    'Content-Length': ' 143',
    'Content-Type': ' application/x-www-form-urlencoded',
    'Host': ' 172.30.4.129',
    'Referer': ' http',
    "User-Agent": ' Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko'}
url_post = r"http://172.30.4.129/a70.htm?isReback=1"
url_loginOut = r"http://172.30.4.129/F.htm"


def staticIp():
    path_ = getcwd() + r"\support\static_ip.bat"   # + r" > " + getcwd() + r"\support\log.txt"
    system(path_)
    return 0


def dhcp():
    path_ = getcwd() + r"\support\DHCP.bat"
    system(path_)
    return 0


def login():
    """
    1.构建 请求头，
    :return:
    """
    print("-->  Login 201613010215  <--")
    post(url_post, data=post_information, timeout=3)

    return 0


if __name__ == "__main__":
    system('echo WLAN接口的设置：')
    while True:
        result = 1
        button = input("1: 静态IP    2：DCHP：")
        get(url=url_loginOut)
        print("\n*****  用户登出  *****\n")
        if button == '1': result = staticIp()
        elif button == '2':  result = dhcp()
        else: print('输入错误；')
        if result == 0: break
    # 登录
    sleep(5)
    login()
